//
//  BBJiaPuHomeViewController.m
//  ligenyun
//
//  Created by Mac on 2018/4/9.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGJiaPuHomeViewController.h"
#import "LGCiTangCreateFamilyTreeController.h"
#import "LGZuPyuItemView.h"
#import "LGZuPuPeopleView.h"
#import "LGFindGenTableViewCell.h"
#import "LGZuPuPersonalViewController.h"
#import "LGXunGenNewDetailViewController.h"
@interface LGJiaPuHomeViewController ()

@end

@implementation LGJiaPuHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"家谱";
    [self configSubView];
    // Do any additional setup after loading the view.
}
#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 40)];
    header.backgroundColor = self.tableView.backgroundColor;
    
    __weak typeof(self) weakSelf =  self;
    STButton * lingyuanButton = [[STButton alloc] initWithFrame:CGRectMake(15, 20, UIScreenWidth - 30, 44)
                                                          title:@"创建族谱"
                                                     titleColor:FirstTextColor
                                                      titleFont:18
                                                   cornerRadius:0
                                                backgroundColor:nil
                                                backgroundImage:[UIImage imageNamed:@"创建私人陵园bg"]
                                                          image:nil];
    [lingyuanButton setClicAction:^(UIButton *sender) {
        [weakSelf.navigationController pushViewController:[LGCiTangCreateFamilyTreeController new] animated:YES];
    }];
    lingyuanButton.centerX = UIScreenWidth / 2;
    lingyuanButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [header addSubview:lingyuanButton];
    
    UIView * header1 = [TMUtils headerViewWithTitle:@"猜你喜欢" moreButtonAction:^(UIButton *sender) {
        
    }];
    header1.top = lingyuanButton.bottom + 20;
    [header addSubview:header1];
    
    
    LGZuPyuItemView * view1 = [[LGZuPyuItemView alloc] initWithFrame:CGRectMake(0, header1.top, UIScreenWidth / 2, 90)];
    view1.left = 0;
    view1.top = header1.bottom;
    [header addSubview:view1];
    
    LGZuPyuItemView * view2 = [[LGZuPyuItemView alloc] initWithFrame:CGRectMake(0, header1.top, UIScreenWidth / 2, 90)];
    view2.left = view1.right;
    view2.top = header1.bottom;
    [header addSubview:view2];
    
    UIView * header2 = [TMUtils headerViewWithTitle:@"可能是您的同族宗亲" moreButtonAction:^(UIButton *sender) {
        
    }];
    header2.top = view2.bottom + 10;
    [header addSubview:header2];
    
    CGFloat viewWith = (UIScreenWidth - 30 - 20)/3;
    LGZuPuPeopleView * people1 = [[LGZuPuPeopleView alloc] initWithFrame:CGRectMake(15, header2.bottom, viewWith, 160)];
    [people1.friendButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedAddFirendView];
    }];
    [header addSubview:people1];
    
    LGZuPuPeopleView * people2 = [[LGZuPuPeopleView alloc] initWithFrame:CGRectMake(15, header2.bottom, viewWith, 160)];
    people2.left = people1.right + 10;
    [people2.friendButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedAddFirendView];
    }];
    [header addSubview:people2];
    
    LGZuPuPeopleView * people3 = [[LGZuPuPeopleView alloc] initWithFrame:CGRectMake(15, header2.bottom, viewWith, 160)];
    people3.left = people2.right + 10;
    [people3.friendButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedAddFirendView];
    }];
    [header addSubview:people3];
    
    UIView * header3 = [TMUtils headerViewWithTitle:@"热点新闻" moreButtonAction:^(UIButton *sender) {
        
    }];
    header3.top = people3.bottom + 10;
    [header addSubview:header3];
    
    header.height = header3.bottom;
    self.tableView.tableHeaderView = header;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [LGFindGenTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    LGFindGenTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[LGFindGenTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.navigationController pushViewController:[LGXunGenNewDetailViewController new] animated:YES];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method
- (void)onSelctedAddFirendView{
    [self.navigationController pushViewController:[LGZuPuPersonalViewController new] animated:YES];
}
@end
